package com.oxygen.pt.mapper;

import com.oxygen.pt.pojo.entity.OxygenChamberInspection;
import com.oxygen.pt.pojo.vo.InspectionSimpleVO;
import com.oxygen.pt.pojo.vo.OxygenChamberInspectionPageVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface OxygenChamberInspectionDailyMapper {

    int insert(OxygenChamberInspection oxygenChamberInspection);

    boolean existsByInspectDate(LocalDate inspectDate);

    boolean deleteById(Long id);

    boolean existsByInspectDateAndChamberId(@Param("inspectDate") LocalDate inspectDate,
                                            @Param("chamberId") Long chamberId);

    @Select("SELECT * FROM oxygen_chamber_inspection_daily WHERE id = #{id}")
    OxygenChamberInspection selectById(Long id);

    List<OxygenChamberInspectionPageVO> selectPageByDateRange(LocalDate start, LocalDate end);

    int updateById(OxygenChamberInspection record);

    @Select("SELECT inspect_date      AS inspectDate," +
            "       inspector," +
            "       power_supply      AS powerSupply," +
            "       computer_system   AS computerSystem," +
            "       lighting_system   AS lightingSystem," +
            "       oxygen_device     AS oxygenDevice," +
            "       meter_status      AS meterStatus," +
            "       flow_switch       AS flowSwitch," +
            "       electric_parts    AS electricParts " +
            "FROM oxygen_chamber_inspection_daily " +
            "WHERE DATE_FORMAT(inspect_date, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m') " +
            "ORDER BY inspect_date")
    List<InspectionSimpleVO> listCurrentMonthForExport();
}
